﻿using System.Collections.Generic;
using System.Device.Location;
using Caliburn.Micro;
using Ninject;
using Spotted.Data.Entities;
using Spotted.Data.Repositories;

namespace Spotted.ViewModels 
{
    public class MainPageViewModel : ViewModelBase
    {
        private readonly INavigationService _navigationService;

        // Deps
        [Inject]
        public IPlacesRepository PlacesRepository { get; set; }

        public double CenterLatitude { get; set; }
        public double CenterLongitude { get; set; }

        public IList<Place> PlacesListing
        {
            get { return PlacesRepository.Places; }
        }

        [Inject]
        public MainPageViewModel(INavigationService navigationService) : base(navigationService)
        {
            // assign the private members
            _navigationService = navigationService;

            // remove our previous entry
            navigationService.RemoveBackEntry();
        }

        // methods
        public void AddLocation()
        {
            double latitude = CenterLatitude;
            double longitude = CenterLongitude;

            _navigationService.UriFor<AddLocationViewModel>()
                .WithParam(ad => ad.CenterLatitude, latitude)
                .WithParam(ad => ad.CenterLongitude, longitude)
                .Navigate();
        }

        public void ShowMap()
        {
            _navigationService.UriFor<PlacesMapViewModel>().Navigate();
        }

        public void PlaceSelected(Place place)
        {
            return;
        }
    }
}
